<template>
  <!-- 后台管理系统主界面 -->
  <div class="wrapper">
    <el-container>
      <el-header>
        <!-- 头 -->
        <el-header style="text-align: right; font-size: 12px">
          <!-- 系统标题 -->
          <el-dropdown @command="handleCommand">
            <i class="el-icon-setting" style="margin-right: 15px"></i>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="center">个人中心</el-dropdown-item>
              <el-dropdown-item command="updatePassword">修改密码</el-dropdown-item>
              <el-dropdown-item command="exit">退出</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>您好，
          <span>{{name}}</span>
        </el-header>
      </el-header>
      <el-container>
        <el-aside width="200px">
          <!-- 侧边 -->
          <!-- 默认展开的索引default-active -->
          <el-menu :default-active="default_active" @select="handleSelect" unique-opened>
            <el-menu-item index="0" v-if="!isTeacher">
              <i class="el-icon-setting"></i>
              <router-link to="/systemdata" class="menu-link">系统数据</router-link>
            </el-menu-item>

            <el-submenu index="1">
              <template slot="title">
                <i class="el-icon-s-data"></i>
                <span>排课管理</span>
              </template>
              <el-menu-item index="1-1" v-if="!isTeacher">
                <router-link to="/classtasklist" class="menu-link">课程任务</router-link>
              </el-menu-item>
              <el-menu-item index="/coursetable">
                <router-link to="/coursetable" class="menu-link">
                  <i class="el-icon-date"></i>
                  <span>课程表</span>
                </router-link>
              </el-menu-item>
              <el-menu-item index="/teacher-schedule">
                <router-link to="/teacher-schedule" class="menu-link">
                  <i class="el-icon-user"></i>
                  <span>教师课表</span>
                </router-link>
              </el-menu-item>
              <el-menu-item index="/classroom-schedule">
                <router-link to="/classroom-schedule" class="menu-link">
                  <i class="el-icon-office-building"></i>
                  <span>教室课表</span>
                </router-link>
              </el-menu-item>
            </el-submenu>

            <el-submenu index="3" v-if="!isTeacher">
              <template slot="title">
                <i class="el-icon-user"></i>
                <span>讲师管理</span>
              </template>
              <el-menu-item-group>
                <el-menu-item index="3-1">
                  <router-link to="/teacherlist" class="menu-link">所有讲师</router-link>
                </el-menu-item>
              </el-menu-item-group>
            </el-submenu>

            <el-submenu index="4">
              <template slot="title">
                <i class="el-icon-box"></i>
                <span>班级管理</span>
              </template>
              <el-menu-item-group>
                <el-menu-item index="4-1">
                  <router-link to="/classmanager" class="menu-link">所有班级</router-link>
                </el-menu-item>
              </el-menu-item-group>
            </el-submenu>

            <el-submenu index="5">
              <template slot="title">
                <i class="el-icon-user"></i>
                <span>学生管理</span>
              </template>
              <el-menu-item-group>
                <el-menu-item index="5-1">
                  <router-link to="/studentlist" class="menu-link">所有学生</router-link>
                </el-menu-item>
              </el-menu-item-group>
            </el-submenu>

            <el-submenu index="6">
              <template slot="title">
                <i class="el-icon-notebook-1"></i>
                <span>教学资料</span>
              </template>
              <el-menu-item index="6-1">
                <router-link to="/courseinfolist" class="menu-link">教材列表</router-link>
              </el-menu-item>
            </el-submenu>

            <el-submenu index="7" v-if="!isTeacher">
              <template slot="title">
                <i class="el-icon-office-building"></i>
                <span>教学设施</span>
              </template>
              <el-menu-item index="7-1">
                <router-link to="/teachbuildinglist" class="menu-link">教学楼管理</router-link>
              </el-menu-item>
              <el-menu-item index="7-2">
                <router-link to="/classroomlist" class="menu-link">教室列表</router-link>
              </el-menu-item>
              <el-menu-item index="7-3">
                <router-link to="/setteacharea" class="menu-link">教学区域安排</router-link>
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>

        <el-main>
          <!-- Main区域，数据显示 -->
          <router-view></router-view>
        </el-main>

      </el-container>
      <!-- 显示系统时间 -->
      <el-footer>{{time}}</el-footer>
    </el-container>
  </div>
</template>

<script>
export default {
  name: "ManagerMain",
  data() {
    return {
      time: "",
      default_active: "0",
      name: '用户名',
    };
  },
  computed: {
    isTeacher:()=>{
      return window.localStorage.getItem('teacher') != null;
    }
  },
  mounted() {
    setInterval(() => {
      this.getTime();
    }, 1000);
    
    let admin = window.localStorage.getItem('admin')
    if(admin != null){
      this.name = (JSON.parse(admin)).realname
    } else {
      let teacher = window.localStorage.getItem('teacher')
      if (teacher != null) {
        this.name = (JSON.parse(teacher)).realname
      }
    }
  },

  methods: {
    // 下拉菜单功能，退出、个人中心
    handleCommand(command) {
      // alert(command)
      if (command == 'exit') {
        localStorage.removeItem('token')
        localStorage.removeItem('admin')
        localStorage.removeItem('teacher')
        // 判断，返回指定页面
        this.$router.push('/')
      } else if (command == 'center') {
        // 跳转到个人中心
      } else if (command == 'updatePassword') {
        // 修改密码页面
        this.$router.push('/updatepass')
      }
      
    },

    // 获取系统时间
    getTime() {
      this.time = new Date().toLocaleString();
    },

    // 展开一个菜单
    handleSelect(val) {
      this.default_active = val;
    }
  }
};
</script>

<style lang="less" scoped>
.wrapper {
  height: 100%;
  width: 100%;
  .a {
    text-decoration: none !important;
    color: #303133 !important;
  }
  .links {
    text-decoration: none !important;
    color: #303133 !important;
  }
}

.el-container {
  height: 100%;
  padding: 0;
  margin: 0;
  width: 100%;
}

.el-header,
.el-footer {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
  padding: 10px;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}

.el-menu {
  height: 100%;
  border-right: none;
  
  .el-menu-item {
    display: flex;
    align-items: center;
    cursor: pointer;
    padding: 0 20px;
    
    &:hover {
      background-color: #ecf5ff;
    }
    
    i {
      margin-right: 5px;
    }
  }

  .el-submenu {
    .el-submenu__title {
      display: flex;
      align-items: center;
      padding: 0 20px;
      
      i {
        margin-right: 5px;
      }
    }
  }

  .menu-link {
    flex: 1;
    text-decoration: none;
    color: inherit;
    display: flex;
    align-items: center;
    height: 100%;
    line-height: 56px;
    
    i {
      margin-right: 5px;
    }
  }
}

.el-menu-item-group {
  .el-menu-item {
    padding-left: 40px !important;
  }
}

.el-menu-item.is-active {
  background-color: #ecf5ff;
  color: #409EFF;
  
  .menu-link {
    color: #409EFF;
  }
}
</style>